package main

import (
	"fmt"
	"github.com/golang/protobuf/proto"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"io"
	"Gocode/study.com/RPCandgRPC/grpc/serverstream/model"
	//"net/rpc"
)

func main() {

	names := []string{"小明"}
	//genders := []string{"男", "女"}
	//gender:=models.Gender(0)
	args := &model.UserRequest{
		Name: names,
		Age: *proto.Uint32(20),
		Gender: *proto.Int32(0),
	}
	//连接服务端
	conn, err := grpc.Dial("localhost:9000", grpc.WithInsecure())
	if err != nil {
		//panic(err.Error())
		fmt.Println("grpc.Dial error=", err)
		return
	}
	defer conn.Close()

	gRPCCliect := model.NewGetUserInfoServiceClient(conn)

	user, err := gRPCCliect.GetUserInfo(context.Background(), args)
	if err != nil {
		//panic(err.Error())
		fmt.Println(" gRPCCliect.GetUser error=", err)
		return
	}
	for {
		recvData, err := user.Recv()
		if err == io.EOF{
			fmt.Println("读取结束")
			return
		}
		if err!=nil{
			fmt.Println("client Recv error=", err)
		}
		fmt.Println(recvData)
		if recvData == nil{
			return
		}
	}
}
